(function() {
  app.directive('dirHeader', function() {
    return {
      restrict: 'E',
      templateUrl: 'public/directive/header.html',
      replace: true,
      scope: {},
      controller: function($scope, $state, header_m) {
        $scope.header = header_m;
      },
      link: function(scope, ele, atr) {}
    };
  });

  app.factory('header_m', function($window) {
    return {
      config: { // 配置对象(默认配置)
        txt_l: '',
        fun_l: function() {
          $window.history.back();
        },
        style_l: {
          background: 'url(img/icon-back.png)no-repeat',
          backgroundSize: '0.25rem 0.35rem',
          backgroundPosition: '0.2rem 0.05rem',
        },
        // tabs: [{
        //   txt: '自选',
        //   go: '/zixuan'
        // }, {
        //   txt: '市场',
        //   go: '/market'
        // }],
        // tab_go: function(it) {
        //   console.log(it);
        // },
        tab_show: false,
        title_c: '', // 主标题
        title2_c: '', // 副标题
        txt_r: '',
        style_r: {},
        fun_r: function() {

        },
      },
      css: function(name, size, position, type) {
        return {
          background: 'url(img/' + name + '.png)no-repeat',
          backgroundSize: size || (type === 'left' ? '0.49rem 0.47rem' : '0.45rem 0.47rem'),
          backgroundPosition: position || (type === 'left' ? '0.2rem 0.01rem' : 'center center'),
        };
      },
      set: function(obj) {
        var that = this;
        if ('css_l' in obj) {
          if (obj.css_l) {
            obj.style_l = that.css(obj.css_l.name, obj.css_l.size, obj.css_l.position, 'left');
          } else {
            obj.style_l = {};
          }
        }

        if ('css_r' in obj) {
          if (obj.css_r) {
            obj.style_r = that.css(obj.css_r.name, obj.css_r.size, obj.css_r.position);
          } else {
            obj.style_r = {};
          }
        }

        angular.isObject(obj) ? angular.extend(that, obj) : '';
      },

      reset: function(obj) {
        var that = this;
        var copyed = angular.copy(that.config);
        angular.extend(that, copyed);
      }
    };
  });
})();
